package com.concurrent.data.thread.controller;

import com.concurrent.data.thread.bean.AddOrderReqBean;
import com.concurrent.data.thread.common.Result;
import com.concurrent.data.thread.entity.GoodsOrder;
import com.concurrent.data.thread.service.GoodsOrderService;
import com.concurrent.data.thread.utils.RedisUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 哲思小辉
 * @version 1.0.0
 * @ClassName GoodsOrderController.java
 * @Description 订单控制类
 * @Param
 * @createTime 2020年03月25日 20:35:00
 */
@Component
@RestController
@RequestMapping("goodsOrder")
@Api(value = "订单控制类", tags = "订单控制类")
public class GoodsOrderController {
    /**
     * 服务对象
     */
    @Autowired
    private GoodsOrderService goodsOrderService;

    @PostMapping("addGoodsOrder")
    @ApiOperation(value = "新增订单", notes = "新增订单")
    public Result<GoodsOrder> addGoodsOrder(@RequestBody GoodsOrder goodsOrder) {
        goodsOrder = this.goodsOrderService.insert(goodsOrder);
        return Result.success(goodsOrder);
    }

    @PostMapping("userOrder")
    @ApiOperation(value = "下单", notes = "下单")
    public Result<GoodsOrder> userOrder(@RequestBody AddOrderReqBean addOrderReqBean) throws Exception {
        val goodsOrder = this.goodsOrderService.addOrder(addOrderReqBean);
        return Result.success(goodsOrder);
    }
}